package com.yeqian.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author : yeqian
 * @Date : 2020/12/25 22:23
 * WebMVC自定义配置
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

        /**
         * 博客前台页面跳转
         */
        registry.addViewController("yeqian-blog").setViewName("front/blog-list");
        registry.addViewController("resume.html").setViewName("front/resume");
        registry.addViewController("tag.html").setViewName("front/tag");
        registry.addViewController("bolg-details.html").setViewName("front/bolg-details");

        /**
         * 管理后台页面跳转
         */
        registry.addViewController("/main-table.html").setViewName("admin/main-table");
        registry.addViewController("/comment-table.html").setViewName("admin/comment-table");
        registry.addViewController("article-edit.html").setViewName("admin/article-edit");
        registry.addViewController("recovery-table.html").setViewName("admin/recovery-table");
        registry.addViewController("draft-table.html").setViewName("admin/draft-table");
        registry.addViewController("tags-table.html").setViewName("admin/tags-table");
        registry.addViewController("classification-table.html").setViewName("admin/classification-table");
        registry.addViewController("main.html").setViewName("admin/main");
        registry.addViewController("my-profile.html").setViewName("admin/my-profile");
        registry.addViewController("/index").setViewName("admin/home");
        registry.addViewController("test").setViewName("test");
        registry.addViewController("/regist.html").setViewName("admin/regist");

        /**
         * 登录跳转
         */
        registry.addViewController("/login").setViewName("login");
    }

    @Autowired
    RedisUrlCountInterceptor interceptor;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor)
                // 拦截所有请求
                .addPathPatterns("/bolg-details.html/**")
                // 放行静态资源
                .excludePathPatterns("/");
    }
}
